# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://docs.scrapy.org/en/latest/topics/item-pipeline.html


# useful for handling different item types with a single interface
from itemadapter import ItemAdapter

import csv

class DangdangPipeline:
    def __init__(self):
        self.filt = open('商品信息.csv',mode='w',encoding='utf-8-sig',newline='')
        self.csvwriter = csv.writer(self.filt)
        self.csvwriter.writerow(['标题','价格','公司','评价'])


    def process_item(self, item, spider):
        self.csvwriter.writerow([item['title'],item['money'],item['company'],item['reviews']])

        return item


    def close_csv(self,spider):
        self.filt.close()

